/***************************************************************************
 * 文件名：CustomNavBarGroup
 * 功能：
 * 说明： 自定义NavBarGroup
 * -------------------------------------------------------------------------
 * 创建时间：2025/7/17 8:50:26
 * 创建人：葛浩
 * 邮箱： 2094733071@qq.com
 * =========================================================================
 *
 * 修改人：   
 * 修改时间：   
 * 修改说明：   
 ***************************************************************************/
using DevExpress.XtraNavBar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeGenerator
{
	public class CustomNavBarGroup: NavBarGroup
	{
		public CustomNavBarGroup()
		   : base()
		{
		}

		public CustomNavBarGroup(string caption)
			: base(caption)
		{
		}

		//重写展开折叠属性,在set中触发自己定义的事件  
		private bool _Expanded = false;
		/// <summary>  
		/// 展开折叠属性  
		/// </summary>  
		public override bool Expanded
		{
			get
			{
				return _Expanded;
			}
			set
			{
				//触发改变之前的事件  
				CancelEventArgs args = new CancelEventArgs() { Cancel = false };
				OnExpandChanging(args);

				//是否可以展开,是否取消,是否与上次一值想等  
				if (CanExpand && !args.Cancel)
				{
					base.Expanded = _Expanded = value;
					//触发修改之后的事件  
					OnExpandChanged(new ExpandedEventArgs(value));
				}
			}
		}

		//是否能够折叠或者展开,有的时候我们需要这个功能  
		private bool _CanExpand = true;
		/// <summary>  
		/// 是否能够展开折叠(为false时,则不能展开或者折叠)  
		/// </summary>  
		public virtual bool CanExpand
		{
			get { return _CanExpand; }
			set { _CanExpand = value; }
		}

		/// <summary>  
		/// 展开或者折叠之后  
		/// </summary>  
		public event EventHandler<ExpandedEventArgs> ExpandChanged;
		protected virtual void OnExpandChanged(ExpandedEventArgs e)
		{
			ExpandChanged?.Invoke(this, e);
		}

		/// <summary>  
		/// 展开或者折叠之前  
		/// </summary>  
		public event EventHandler<CancelEventArgs> ExpandChanging;
		protected virtual void OnExpandChanging(CancelEventArgs e)
		{
			ExpandChanging?.Invoke(this, e);
		}
	}

	public class ExpandedEventArgs : EventArgs
	{
		public ExpandedEventArgs()
		{
			Expanded = false;
		}

		public ExpandedEventArgs(bool expanded)
		{
			Expanded = expanded;
		}

		/// <summary>  
		/// 展开或者折叠  
		/// </summary>  
		public bool Expanded { get; set; }
	}

}
